<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');        
/**
* hàm gửi email có templates
* author khanhdq119@gmail.com
* @param mixed $email_Tpl
* @param mixed $email
* @param mixed $args
*/
function sendMailTpl($email_Tpl,$email="nobody@domain.com",$args=array())
{
	require(APPPATH."ext_libraries/phpmailer/class.phpmailer.php");
	$mail = new PHPMailer(); 
	$mail->IsSMTP();
	$content = $email_Tpl;   
	foreach($args as $key=>$v)  
	{
		$content = str_replace("$$key",$v,$content);
	}
	try {
	$mail->Host       = "mb2d185.vdrs.net"; // SMTP server
	$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
							                   // 1 = errors and messages
							                   // 2 = messages only
	$mail->SMTPAuth   = true;                  // enable SMTP authentication
	$mail->SMTPSecure = 'ssl';          
	$mail->Host       = "mb2d185.vdrs.net"; // sets the SMTP server
	$mail->Port       = 465;                    // set the SMTP port for the GMAIL server
	$mail->Username   = "admin@thitruongthe.com"; // SMTP account username
	$mail->Password   = "vietnam@rev";        // SMTP account password
	$mail->CharSet	  = "utf-8";  
	$mail->SetFrom('admin@thitruongthe.com', 'Chìa Khóa Vàng');
	//$mail->AddCC("khanhdq119@gmail.com","Chìa Khóa Vàng");    
   // $mail->AddCC("sales@chiakhoavang.vn","Thẻ đã bán");     
	$mail->Subject    = "Thông tin thẻ Visa mua vào lúc ". date("g:i a F j, Y") ;

	$mail->AltBody    = "Cảm ơn quý khách đã sử dụng dịch vụ của chúng tôi!"; // optional, comment out and test

	$address = $email;
	$mail->AddAddress($email, "Chìa Khóa Vàng");
	$mail->IsHTML(true);
	  $mail->Body    = stripslashes($content); 
	  $mail->Send();
	  	return TRUE;
	} catch (phpmailerException $e) {
	  	return FALSE; //Pretty error messages from PHPMailer
	} catch (Exception $e) {
	  	return FALSE; //Boring error messages from anything else!
	}                                
	unset($subject);
	unset($content);
	unset($receivers);
	unset($mail);						
}
